﻿using System;
using System.Collections.Generic;
using System.Text;

using Spring.Transaction.Interceptor;

using efish.Framework.Model;
using efish.Framework.Dao;

namespace efish.Framework.Service
{
    public class StoreService : BaseService, IStoreService
    {
        #region DAOs

        private CategoriesDAO _categorysDAO;
        public CategoriesDAO CategoriesDAO
        {
            get { return _categorysDAO; }
            set { _categorysDAO = value; }
        }

        private ProductsDAO _productsDAO;
        public ProductsDAO ProductsDAO
        {
            get { return _productsDAO; }
            set { _productsDAO = value; }
        }

        private ReviewDAO _reviewDAO;
        public ReviewDAO ReviewDAO
        {
            get { return _reviewDAO; }
            set { _reviewDAO = value; }
        }

        #endregion

        #region Categories

        [Transaction(ReadOnly = false)]
        public void CreateCategory(Category item)
        {
            _categorysDAO.Save(item);
        }
        [Transaction(ReadOnly = false)]
        public void UpdateCategory(Category item)
        {
            _categorysDAO.Update(item);
        }
        [Transaction(ReadOnly = false)]
        public void DeleteCategory(Category item)
        {
            _categorysDAO.Delete(item);
        }
        [Transaction(ReadOnly = false)]
        public void DeleteCategoryByID(int id)
        {
            _categorysDAO.DeleteByID(id);
        }

        public Category GetCategory(int id)
        {
            return _categorysDAO.Get(id);
        }
        public IList<Category> GetCategories()
        {
            return _categorysDAO.GetAll();
        }
        public IList<Category> GetTopCategories()
        {
            return _categorysDAO.GetTopCategories();
        }

        public IList<Category> GetCategories(int categoryid)
        {
            return _categorysDAO.GetCategories(categoryid);
        }

        #endregion

        #region Products

        [Transaction(ReadOnly = false)]
        public void CreateProduct(Product item)
        {
            _productsDAO.Save(item);
        }
        [Transaction(ReadOnly = false)]
        public void UpdateProduct(Product item)
        {
            _productsDAO.Update(item);
        }
        [Transaction(ReadOnly = false)]
        public void DeleteProduct(Product item)
        {
            _productsDAO.Delete(item);
        }
        [Transaction(ReadOnly = false)]
        public void DeleteProductID(int id)
        {
            _productsDAO.DeleteByID(id);
        }

        public Product GetProduct(int id)
        {
            return _productsDAO.Get(id);
        }
        public IList<Product> GetProducts()
        {
            return _productsDAO.GetAll();
        }

        #endregion

        #region Reviews

        [Transaction(ReadOnly = false)]
        public void CreateReview(Review item)
        {
            _reviewDAO.Save(item);
        }
        [Transaction(ReadOnly = false)]
        public void UpdateReview(Review item)
        {
            _reviewDAO.Update(item);
        }
        [Transaction(ReadOnly = false)]
        public void DeleteReview(Review item)
        {
            _reviewDAO.Delete(item);
        }
        [Transaction(ReadOnly = false)]
        public void DeleteReviewByID(int id)
        {
            _reviewDAO.DeleteByID(id);
        }

        public Review GetReview(int id)
        {
            return _reviewDAO.Get(id);
        }
        public IList<Review> GetReviews()
        {
            return _reviewDAO.GetAll();
        }

        #endregion
    }

    public interface IStoreService
    {
        #region Categories

        void CreateCategory(Category item);
        
        void UpdateCategory(Category item);
        
        void DeleteCategory(Category item);
        
        void DeleteCategoryByID(int id);

        Category GetCategory(int id);

        IList<Category> GetCategories();

        IList<Category> GetTopCategories();

        IList<Category> GetCategories(int categoryid);

        #endregion

        #region Products

        void CreateProduct(Product item);

        void UpdateProduct(Product item);

        void DeleteProduct(Product item);

        void DeleteProductID(int id);

        Product GetProduct(int id);

        IList<Product> GetProducts();

        #endregion

        #region Reviews

        void CreateReview(Review item);

        void UpdateReview(Review item);

        void DeleteReview(Review item);

        void DeleteReviewByID(int id);

        Review GetReview(int id);
        IList<Review> GetReviews();

        #endregion
    }
}
